/*     */ package net.sourceforge.appgen.model;
/*     */ 
/*     */ import java.io.Serializable;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collections;
/*     */ import java.util.Comparator;
/*     */ import java.util.List;
/*     */ import java.util.regex.Matcher;
/*     */ import java.util.regex.Pattern;
/*     */ import net.sourceforge.appgen.converter.FirstCharacterLowerCaseConverter;
/*     */ import net.sourceforge.appgen.converter.FirstCharacterUpperCaseConverter;
/*     */ import net.sourceforge.appgen.converter.StringConverter;
/*     */ import net.sourceforge.appgen.util.ConventionUtils;
/*     */ import net.sourceforge.appgen.util.FileUtils;
/*     */ 
/*     */ public class Entity extends ValueModifyModel
/*     */   implements Serializable
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*  42 */   private static final StringConverter firstCharacterUpperCaseConverter = new FirstCharacterUpperCaseConverter();
/*     */ 
/*  44 */   private static final StringConverter firstCharacterLowerCaseConverter = new FirstCharacterLowerCaseConverter();
/*     */ 
/*  46 */   private static final Comparator<Field> primaryKeyFieldComparator = new PrimaryKeyFieldComparator();
/*     */   private String tableName;
/*     */   private String baseName;
/*     */   private String packageName;
/*     */   private boolean create;
/*     */   private boolean allFieldSelection;
/*     */   private List<Field> fieldList;
/*     */ 
/*     */   public Entity()
/*     */   {
/*  63 */     this.fieldList = new ArrayList();
/*     */   }
/*     */ 
/*     */   public List<Field> getToStringFieldList() {
/*  67 */     List list = new ArrayList();
/*     */ 
/*  69 */     for (Field field : this.fieldList) {
/*  70 */       if ((field.isCreate()) && ((field.getPkPosition() > 0) || ("AttachFile".equals(field.getFieldType())))) {
/*  71 */         list.add(field);
/*     */       }
/*     */     }
/*     */ 
/*  75 */     Collections.sort(list, primaryKeyFieldComparator);
/*     */ 
/*  77 */     return list;
/*     */   }
/*     */ 
/*     */   public List<Field> getPrimaryKeyFieldList() {
/*  81 */     List list = new ArrayList();
/*     */ 
/*  83 */     for (Field field : this.fieldList) {
/*  84 */       if ((field.isCreate()) && (field.getPkPosition() > 0)) {
/*  85 */         list.add(field);
/*     */       }
/*     */     }
/*     */ 
/*  89 */     Collections.sort(list, primaryKeyFieldComparator);
/*     */ 
/*  91 */     return list;
/*     */   }
/*     */ 
/*     */   public boolean hasAttachFileField() {
/*  95 */     List list = getAttachFileFieldList();
/*     */ 
/*  97 */     return list.size() > 0;
/*     */   }
/*     */ 
/*     */   public List<Field> getAttachFileFieldList() {
/* 101 */     List list = new ArrayList();
/*     */ 
/* 103 */     for (Field field : this.fieldList) {
/* 104 */       if ((field.isCreate()) && ("AttachFile".equals(field.getFieldType()))) {
/* 105 */         list.add(field);
/*     */       }
/*     */     }
/*     */ 
/* 109 */     return list;
/*     */   }
/*     */ 
/*     */   public List<Field> getFieldListExceptLob() {
/* 113 */     List list = new ArrayList();
/*     */ 
/* 115 */     for (Field field : this.fieldList) {
/* 116 */       if ((field.isCreate()) && (!field.isLob())) {
/* 117 */         list.add(field);
/*     */       }
/*     */     }
/*     */ 
/* 121 */     return list;
/*     */   }
/*     */ 
/*     */   public String getToStringStatement() {
/* 125 */     return getToStringStatement("\t\t");
/*     */   }
/*     */ 
/*     */   public String getToStringStatement(String indent) {
/* 129 */     StringBuffer buffer = new StringBuffer();
/* 130 */     buffer.append(indent + "return getClass().getName() + \"@\" + Integer.toHexString(hashCode()) + " + FileUtils.ln());
/* 131 */     buffer.append(indent + "\t" + "\"(\" + " + FileUtils.ln());
/* 132 */     boolean first = true;
/* 133 */     for (Field field : getPrimaryKeyFieldList()) {
/* 134 */       if (!first) {
/* 135 */         buffer.append("\", \" + " + FileUtils.ln());
/*     */       }
/* 137 */       buffer.append(indent + "\t" + "\"" + field.getFieldName() + "=\" + \"'\" + " + field.getFieldName() + " + \"'\" + ");
/* 138 */       first = false;
/*     */     }
/* 140 */     buffer.append(FileUtils.ln());
/* 141 */     buffer.append(indent + "\t" + "\")\";");
/*     */ 
/* 143 */     return buffer.toString();
/*     */   }
/*     */ 
/*     */   public String getInstanceName() {
/* 147 */     return firstCharacterLowerCaseConverter.convert(this.baseName);
/*     */   }
/*     */ 
/*     */   public String getClassName() {
/* 151 */     return firstCharacterUpperCaseConverter.convert(this.baseName);
/*     */   }
/*     */ 
/*     */   public String getFullPackageName() {
/* 155 */     return this.packageName + ".domain";
/*     */   }
/*     */ 
/*     */   public List<String> getImportClassNameList() {
/* 159 */     List list = new ArrayList();
/*     */ 
/* 161 */     list.add("java.io.Serializable");
/*     */ 
/* 163 */     if (this.fieldList != null) {
/* 164 */       for (Field field : this.fieldList) {
							if ((field.isCreate()) && (field.getFieldType().indexOf('.') > 0) && 
			/* 166 */           (field.getSimpleFieldType().equals("String")) && (field.isValidNullable())){
								if((!list.contains("org.hibernate.validator.constraints.NotEmpty"))){
									list.add("org.hibernate.validator.constraints.NotEmpty");
								}
								if((!list.contains("javax.validation.constraints.Size"))){
									list.add("javax.validation.constraints.Size");
								}
							}
				if ((field.isCreate()) &&
						/* 166 */(field.getSimpleFieldType().equals("double"))
						&& (field.isValidNullable())) {
					if ((!list
							.contains("javax.validation.constraints.Digits"))) {
						list.add("javax.validation.constraints.Digits");
					}
				}
/* 165 */         if ((field.isCreate()) && (field.getFieldType().indexOf('.') > 0) && 
/* 166 */           (!field.getFieldType().equals("java.lang." + field.getSimpleFieldType())) && 
/* 167 */           (!list.contains(field.getFieldType()))) {
/* 168 */           list.add(field.getFieldType());
/*     */         }
/*     */ 
/* 172 */         if ((!field.isCreate()) || (!"AttachFile".equals(field.getFieldType())) || 
/* 173 */           (list.contains(getPackageName() + ".base." + "AttachFile"))) continue;
/* 174 */         list.add(getPackageName() + ".base." + "AttachFile");
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 180 */     return list;
/*     */   }
/*     */ 
/*     */   public List<String> getImportDeclarations() {
/* 184 */     List list = new ArrayList();
/* 185 */     list.addAll(getImportClassNameList());
/*     */ 
/* 187 */     return ConventionUtils.getImportDeclarations(list, this.packageName);
/*     */   }
/*     */ 
/*     */   public boolean hasLob() {
/* 191 */     for (Field field : this.fieldList) {
/* 192 */       if ((field.isCreate()) && (field.isLob())) {
/* 193 */         return true;
/*     */       }
/*     */     }
/*     */ 
/* 197 */     return false;
/*     */   }
/*     */ 
/*     */   public boolean isValidTableName() {
/* 201 */     String tableName = getTableName();
/*     */ 
/* 203 */     if (((tableName != null ? 1 : 0) & (tableName.length() == 0 ? 1 : 0)) != 0) {
/* 204 */       return false;
/*     */     }
/*     */ 
/* 208 */     return tableName.indexOf(" ") < 0;
/*     */   }
/*     */ 
/*     */   public boolean isValidBaseName()
/*     */   {
/* 215 */     if (getBaseName() == null) {
/* 216 */       return false;
/*     */     }
/*     */ 
/* 219 */     Pattern p = Pattern.compile("^([a-z]+([a-zA-Z0-9_]+[a-zA-Z0-9_]*)?)$");
/* 220 */     Matcher m = p.matcher(getBaseName());
/*     */ 
/* 222 */     if (!m.matches()) {
/* 223 */       return false;
/*     */     }
/*     */ 
/* 226 */     if (ConventionUtils.isReservedWord(getBaseName())) {
/* 227 */       return false;
/*     */     }
/*     */ 
/* 230 */     return m.matches();
/*     */   }
/*     */ 
/*     */   public boolean hasDuplicateFieldName() {
/* 234 */     for (Field f0 : this.fieldList) {
/* 235 */       for (Field f1 : this.fieldList) {
/* 236 */         if ((f0 != f1) && (f0.isCreate()) && (f1.isCreate()) && (f0.getFieldName().equals(f1.getFieldName()))) {
/* 237 */           return true;
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 242 */     return false;
/*     */   }
/*     */ 
/*     */   public int hashCode()
/*     */   {
/* 248 */     int result = 1;
/* 249 */     result = 31 * result + (this.allFieldSelection ? 1231 : 1237);
/* 250 */     result = 31 * result + (this.baseName == null ? 0 : this.baseName.hashCode());
/* 251 */     result = 31 * result + (this.create ? 1231 : 1237);
/* 252 */     result = 31 * result + (this.fieldList == null ? 0 : this.fieldList.hashCode());
/* 253 */     result = 31 * result + (this.packageName == null ? 0 : this.packageName.hashCode());
/* 254 */     result = 31 * result + (this.tableName == null ? 0 : this.tableName.hashCode());
/* 255 */     return result;
/*     */   }
/*     */ 
/*     */   public boolean equals(Object obj)
/*     */   {
/* 260 */     if (this == obj)
/* 261 */       return true;
/* 262 */     if (obj == null)
/* 263 */       return false;
/* 264 */     if (getClass() != obj.getClass())
/* 265 */       return false;
/* 266 */     Entity other = (Entity)obj;
/* 267 */     if (this.allFieldSelection != other.allFieldSelection)
/* 268 */       return false;
/* 269 */     if (this.baseName == null) {
/* 270 */       if (other.baseName != null)
/* 271 */         return false;
/* 272 */     } else if (!this.baseName.equals(other.baseName))
/* 273 */       return false;
/* 274 */     if (this.create != other.create)
/* 275 */       return false;
/* 276 */     if (this.fieldList == null) {
/* 277 */       if (other.fieldList != null)
/* 278 */         return false;
/* 279 */     } else if (!this.fieldList.equals(other.fieldList))
/* 280 */       return false;
/* 281 */     if (this.packageName == null) {
/* 282 */       if (other.packageName != null)
/* 283 */         return false;
/* 284 */     } else if (!this.packageName.equals(other.packageName))
/* 285 */       return false;
/* 286 */     if (this.tableName == null) {
/* 287 */       if (other.tableName != null)
/* 288 */         return false;
/* 289 */     } else if (!this.tableName.equals(other.tableName))
/* 290 */       return false;
/* 291 */     return true;
/*     */   }
/*     */ 
/*     */   public String getTableName() {
/* 295 */     return this.tableName;
/*     */   }
/*     */ 
/*     */   public void setTableName(String tableName) {
/* 299 */     this.tableName = tableName;
/*     */ 
/* 301 */     valueModified();
/*     */   }
/*     */ 
/*     */   public String getBaseName() {
/* 305 */     return this.baseName;
/*     */   }
/*     */ 
/*     */   public void setBaseName(String baseName) {
/* 309 */     this.baseName = baseName;
/*     */ 
/* 311 */     valueModified();
/*     */   }
/*     */ 
/*     */   public String getPackageName() {
/* 315 */     return this.packageName;
/*     */   }
/*     */ 
/*     */   public void setPackageName(String packageName) {
/* 319 */     this.packageName = packageName;
/*     */   }
/*     */ 
/*     */   public boolean isCreate()
/*     */   {
/* 325 */     return this.create;
/*     */   }
/*     */ 
/*     */   public void setCreate(boolean create) {
/* 329 */     this.create = create;
/*     */ 
/* 331 */     valueModified();
/*     */   }
/*     */ 
/*     */   public boolean isAllFieldSelection() {
/* 335 */     return this.allFieldSelection;
/*     */   }
/*     */ 
/*     */   public void setAllFieldSelection(boolean allFieldSelection) {
/* 339 */     this.allFieldSelection = allFieldSelection;
/*     */ 
/* 341 */     valueModified();
/*     */   }
/*     */ 
/*     */   public List<Field> getFieldList() {
/* 345 */     return this.fieldList;
/*     */   }
/*     */ 
/*     */   public void setFieldList(List<Field> fieldList) {
/* 349 */     this.fieldList = fieldList;
/*     */ 
/* 351 */     valueModified();
/*     */   }
/*     */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.model.Entity
 * JD-Core Version:    0.6.0
 */